;
var mod_pwd_ops = {
    init: function () {
        this.eventBind()
    },
    eventBind: function () {
        $("#save").click(function () {

            console.log('1111');

            let btn_target = $(this);

            // 防止重复点击
            if (btn_target.hasClass('disabled')) {
                common_ops.alert('正在处理，请稍稍');
                return
            }

            let old_password_target = $('#old_password');
            let old_password = old_password_target.val();

            let new_password_target = $('#new_password');
            let new_password = new_password_target.val();

            if ( !old_password ) {
                common_ops.tip('请输入原密码', old_password_target);
                return false
            }

            if ( !new_password || new_password.length < 6) {
                common_ops.tip('请输入不少于6位的新密码', new_password_target);
                return false
            }

            btn_target.addClass("disabled");

            let data = {
                old_password: old_password,
                new_password: new_password
            };

            $.ajax({
                url: common_ops.buildUrl("/user/reset-pwd"),
                type: 'POST',
                data: data,
                dataType: 'json',
                success: function (res) {
                    btn_target.removeClass('disabled');
                    let callback = null;
                    if (res.code == 200) {
                        callback = function () {
                            window.location.href = window.location.href;
                        }
                    }
                    common_ops.alert(res.msg, callback)
                }
            })

        })
    }
}

$(document).ready(function () {
    mod_pwd_ops.init()
})